using System;
using UnityEngine;

namespace ProceduralPrimitivesUtil
{
	public class ChamferBox : PPBase
	{
		[Header("Basic parameters")]
		public float width = 1f;

		public float length = 1f;

		public float height = 1f;

		public float fillet = 0.1f;

		[Header("Segments")]
		public int widthSegs = 2;

		public int lengthSegs = 2;

		public int heightSegs = 2;

		public int filletSegs = 3;

		[Header("Mapping Coordinates")]
		public bool generateMappingCoords = true;

		public bool realWorldMapSize;

		public Vector2 UVOffset = new Vector2(0f, 0f);

		public Vector2 UVTiling = new Vector2(1f, 1f);

		[Header("Others")]
		public bool flipNormals;

		public bool smooth = true;

		protected override void CreateMesh()
		{
			m_mesh.name = "Chamfer Box";
			length = Mathf.Clamp(length, 1E-05f, 10000f);
			width = Mathf.Clamp(width, 1E-05f, 10000f);
			height = Mathf.Clamp(height, 1E-05f, 10000f);
			float num = ((length < width) ? length : width);
			num = ((num < height) ? num : height);
			fillet = Mathf.Clamp(fillet, 1E-05f, num / 2f);
			lengthSegs = Mathf.Clamp(lengthSegs, 1, 100);
			widthSegs = Mathf.Clamp(widthSegs, 1, 100);
			heightSegs = Mathf.Clamp(heightSegs, 1, 100);
			filletSegs = Mathf.Clamp(filletSegs, 1, 100);
			float num2 = length * 0.5f;
			float num3 = width * 0.5f;
			float num4 = height * 0.5f;
			float num5 = num2 - fillet;
			float num6 = num3 - fillet;
			float num7 = num4 - fillet;
			float num8 = num5 * 2f;
			float num9 = num6 * 2f;
			float num10 = num7 * 2f;
			Vector2 vector = (realWorldMapSize ? new Vector2(1f, 1f) : new Vector2(0.25f, 1f));
			Vector2 vector2 = (realWorldMapSize ? new Vector2(1f, 1f) : new Vector2(0.25f, 1f));
			vector = new Vector2(UVTiling.x * vector.x, UVTiling.y * vector.y);
			vector2 = new Vector2(UVTiling.x * vector2.x, UVTiling.y * vector2.y);
			CreatePlane(pivotOffset + m_rotation * new Vector3(0f, 0f, 0f - num2), m_rotation * Vector3.up, m_rotation * Vector3.right, num9, num10, widthSegs, heightSegs, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, flipNormals);
			CreatePlane(pivotOffset + m_rotation * new Vector3(0f, 0f, num2), m_rotation * Vector3.up, m_rotation * Vector3.left, num9, num10, widthSegs, heightSegs, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, flipNormals);
			CreatePlane(pivotOffset + m_rotation * new Vector3(0f - num3, 0f, 0f), m_rotation * Vector3.up, m_rotation * Vector3.back, num8, num10, lengthSegs, heightSegs, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, flipNormals);
			CreatePlane(pivotOffset + m_rotation * new Vector3(num3, 0f, 0f), m_rotation * Vector3.up, m_rotation * Vector3.forward, num8, num10, lengthSegs, heightSegs, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, flipNormals);
			CreatePlane(pivotOffset + m_rotation * new Vector3(0f, num4, 0f), m_rotation * Vector3.forward, m_rotation * Vector3.right, num9, num8, widthSegs, lengthSegs, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, flipNormals);
			CreatePlane(pivotOffset + m_rotation * new Vector3(0f, 0f - num4, 0f), m_rotation * Vector3.forward, m_rotation * Vector3.left, num9, num8, widthSegs, lengthSegs, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, flipNormals);
			CreateCylinder(pivotOffset + m_rotation * new Vector3(num6, 0f, num5), m_rotation * Vector3.forward, m_rotation * Vector3.right, num10, fillet, filletSegs, heightSegs, sliceOn: true, 0f, 90f, generateMappingCoords, realWorldMapSize, UVOffset + new Vector2(0f, 0f), vector, flipNormals, smooth);
			CreateCylinder(pivotOffset + m_rotation * new Vector3(num6, 0f, 0f - num5), m_rotation * Vector3.forward, m_rotation * Vector3.right, num10, fillet, filletSegs, heightSegs, sliceOn: true, 90f, 180f, generateMappingCoords, realWorldMapSize, UVOffset + new Vector2(0.25f, 0f), vector, flipNormals, smooth);
			CreateCylinder(pivotOffset + m_rotation * new Vector3(0f - num6, 0f, 0f - num5), m_rotation * Vector3.forward, m_rotation * Vector3.right, num10, fillet, filletSegs, heightSegs, sliceOn: true, 180f, 270f, generateMappingCoords, realWorldMapSize, UVOffset + new Vector2(0.5f, 0f), vector, flipNormals, smooth);
			CreateCylinder(pivotOffset + m_rotation * new Vector3(0f - num6, 0f, num5), m_rotation * Vector3.forward, m_rotation * Vector3.right, num10, fillet, filletSegs, heightSegs, sliceOn: true, 270f, 360f, generateMappingCoords, realWorldMapSize, UVOffset + new Vector2(0.75f, 0f), vector, flipNormals, smooth);
			CreateCylinder(pivotOffset + m_rotation * new Vector3(num6, 0f - num7, 0f), m_rotation * Vector3.down, m_rotation * Vector3.right, num8, fillet, filletSegs, lengthSegs, sliceOn: true, 0f, 90f, generateMappingCoords, realWorldMapSize, UVOffset + new Vector2(0f, 0f), vector, flipNormals, smooth);
			CreateCylinder(pivotOffset + m_rotation * new Vector3(num6, num7, 0f), m_rotation * Vector3.down, m_rotation * Vector3.right, num8, fillet, filletSegs, lengthSegs, sliceOn: true, 90f, 180f, generateMappingCoords, realWorldMapSize, UVOffset + new Vector2(0.25f, 0f), vector, flipNormals, smooth);
			CreateCylinder(pivotOffset + m_rotation * new Vector3(0f - num6, num7, 0f), m_rotation * Vector3.down, m_rotation * Vector3.right, num8, fillet, filletSegs, lengthSegs, sliceOn: true, 180f, 270f, generateMappingCoords, realWorldMapSize, UVOffset + new Vector2(0.5f, 0f), vector, flipNormals, smooth);
			CreateCylinder(pivotOffset + m_rotation * new Vector3(0f - num6, 0f - num7, 0f), m_rotation * Vector3.down, m_rotation * Vector3.right, num8, fillet, filletSegs, lengthSegs, sliceOn: true, 270f, 360f, generateMappingCoords, realWorldMapSize, UVOffset + new Vector2(0.75f, 0f), vector, flipNormals, smooth);
			CreateCylinder(pivotOffset + m_rotation * new Vector3(0f, 0f - num7, num5), m_rotation * Vector3.forward, m_rotation * Vector3.down, num9, fillet, filletSegs, widthSegs, sliceOn: true, 0f, 90f, generateMappingCoords, realWorldMapSize, UVOffset + new Vector2(0f, 0f), vector, flipNormals, smooth);
			CreateCylinder(pivotOffset + m_rotation * new Vector3(0f, 0f - num7, 0f - num5), m_rotation * Vector3.forward, m_rotation * Vector3.down, num9, fillet, filletSegs, widthSegs, sliceOn: true, 90f, 180f, generateMappingCoords, realWorldMapSize, UVOffset + new Vector2(0.25f, 0f), vector, flipNormals, smooth);
			CreateCylinder(pivotOffset + m_rotation * new Vector3(0f, num7, 0f - num5), m_rotation * Vector3.forward, m_rotation * Vector3.down, num9, fillet, filletSegs, widthSegs, sliceOn: true, 180f, 270f, generateMappingCoords, realWorldMapSize, UVOffset + new Vector2(0.5f, 0f), vector, flipNormals, smooth);
			CreateCylinder(pivotOffset + m_rotation * new Vector3(0f, num7, num5), m_rotation * Vector3.forward, m_rotation * Vector3.down, num9, fillet, filletSegs, widthSegs, sliceOn: true, 270f, 360f, generateMappingCoords, realWorldMapSize, UVOffset + new Vector2(0.75f, 0f), vector, flipNormals, smooth);
			CreateSphere(pivotOffset + m_rotation * new Vector3(num6, num7, num5), m_rotation * Vector3.forward, m_rotation * Vector3.right, fillet, filletSegs, filletSegs * 2, sliceOn: true, 0f, 90f, hemiSphere: true, MathF.PI / 2f, MathF.PI, generateMappingCoords, realWorldMapSize, UVOffset + new Vector2(0f, 0f), vector2, flipNormals, smooth);
			CreateSphere(pivotOffset + m_rotation * new Vector3(num6, num7, 0f - num5), m_rotation * Vector3.forward, m_rotation * Vector3.right, fillet, filletSegs, filletSegs * 2, sliceOn: true, 90f, 180f, hemiSphere: true, MathF.PI / 2f, MathF.PI, generateMappingCoords, realWorldMapSize, UVOffset + new Vector2(0.25f, 0f), vector2, flipNormals, smooth);
			CreateSphere(pivotOffset + m_rotation * new Vector3(0f - num6, num7, 0f - num5), m_rotation * Vector3.forward, m_rotation * Vector3.right, fillet, filletSegs, filletSegs * 2, sliceOn: true, 180f, 270f, hemiSphere: true, MathF.PI / 2f, MathF.PI, generateMappingCoords, realWorldMapSize, UVOffset + new Vector2(0.5f, 0f), vector2, flipNormals, smooth);
			CreateSphere(pivotOffset + m_rotation * new Vector3(0f - num6, num7, num5), m_rotation * Vector3.forward, m_rotation * Vector3.right, fillet, filletSegs, filletSegs * 2, sliceOn: true, 270f, 360f, hemiSphere: true, MathF.PI / 2f, MathF.PI, generateMappingCoords, realWorldMapSize, UVOffset + new Vector2(0.75f, 0f), vector2, flipNormals, smooth);
			CreateSphere(pivotOffset + m_rotation * new Vector3(num6, 0f - num7, num5), m_rotation * Vector3.forward, m_rotation * Vector3.right, fillet, filletSegs, filletSegs * 2, sliceOn: true, 0f, 90f, hemiSphere: true, 0f, MathF.PI / 2f, generateMappingCoords, realWorldMapSize, UVOffset + new Vector2(0f, 0f), vector2, flipNormals, smooth);
			CreateSphere(pivotOffset + m_rotation * new Vector3(num6, 0f - num7, 0f - num5), m_rotation * Vector3.forward, m_rotation * Vector3.right, fillet, filletSegs, filletSegs * 2, sliceOn: true, 90f, 180f, hemiSphere: true, 0f, MathF.PI / 2f, generateMappingCoords, realWorldMapSize, UVOffset + new Vector2(0.25f, 0f), vector2, flipNormals, smooth);
			CreateSphere(pivotOffset + m_rotation * new Vector3(0f - num6, 0f - num7, 0f - num5), m_rotation * Vector3.forward, m_rotation * Vector3.right, fillet, filletSegs, filletSegs * 2, sliceOn: true, 180f, 270f, hemiSphere: true, 0f, MathF.PI / 2f, generateMappingCoords, realWorldMapSize, UVOffset + new Vector2(0.5f, 0f), vector2, flipNormals, smooth);
			CreateSphere(pivotOffset + m_rotation * new Vector3(0f - num6, 0f - num7, num5), m_rotation * Vector3.forward, m_rotation * Vector3.right, fillet, filletSegs, filletSegs * 2, sliceOn: true, 270f, 360f, hemiSphere: true, 0f, MathF.PI / 2f, generateMappingCoords, realWorldMapSize, UVOffset + new Vector2(0.75f, 0f), vector2, flipNormals, smooth);
		}
	}
}
